package com.example.conditionBase.specialCondition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;


/**
 *  自定义的条件注解,根据自定义规则,
 *  配置是否生成某些bean
 *  @author hexiaowu
 *
 */
public class SpecialConditionAnnotion implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        // 如果存在 specialA跟specialB 则返回true
        if(beanFactory.containsBean("specailA")&&beanFactory.containsBean("specialB")){
            return true;
        }


        return false;
    }
}
